package de.clapp.musicbox;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import de.clapp.R;
import de.clapp.musicbox.loader.MusicBoxLoader;
import de.clapp.musicbox.viewpages.AlbumMusicFragmentList;
import de.clapp.musicbox.viewpages.CurrentlyPlayingMusicFragmentList;
import de.clapp.musicbox.viewpages.InterpretMusicFragmentList;
import de.clapp.musicbox.viewpages.TitleMusicFragmentList;
//import android.app.Fragment;
import de.clapp.toolkit.OneSideSwipeableViewPager;

public class MusicFragment extends Fragment
{
    public static OneSideSwipeableViewPager myViewPager;

    private MusicPageAdapter musicPageAdapter;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        super.onCreateView(inflater, container, savedInstanceState);
        this.musicPageAdapter = new MusicPageAdapter(getChildFragmentManager());

        View view = inflater.inflate(R.layout.music_pager, container, false);
        myViewPager = (OneSideSwipeableViewPager) view.findViewById(R.id.pager);
        myViewPager.setAdapter(musicPageAdapter);
        myViewPager.setCurrentItem(0);
        
        this.musicPageAdapter.addFragment(new CurrentlyPlayingMusicFragmentList());
        this.musicPageAdapter.addFragment(new InterpretMusicFragmentList());
        this.musicPageAdapter.addFragment(new AlbumMusicFragmentList());
        this.musicPageAdapter.addFragment(new TitleMusicFragmentList());
        
        this.getLoaderManager().initLoader(MusicBoxLoader.MUSICBOXLOADER_ID, null, MusicModel.getI()).forceLoad();

        return view;
    }
    
    @Override
    public void onResume()
    { 
        super.onResume();
        MusicVoteModel.getI().setFragment(this);
        MusicVoteModel.getI().startListeningForVotes();
    }
    
    @Override
    public void onPause()
    {
        super.onPause();
        MusicVoteModel.getI().stopListeningForVotes();
    }

}
